#!/usr/bin/env python
# encoding: UTF-8

__version__ = "$Id$"

import db_cleanup
import os
from contacts import ContactFile
import logging

TEST_CONTACT = """HBPLUS Hydrogen Bond Calculator v 3.15            Nov 13 17:34:59 CET 2009
(c) I McDonald, D Naylor, D Jones and J Thornton 1993 All Rights Reserved.
Citing HBPLUS in publications that use these results is condition of use.
9TTT <- Brookhaven Code "9TTT.pdb.new" <- PDB file                         
<---DONOR---> <-ACCEPTOR-->    atom                        ^               
c    i                          cat <-CA-CA->   ^        H-A-AA   ^      H- 
h    n   atom  resd res      DA  || num        DHA   H-A  angle D-A-AA Bond
n    s   type  num  typ     dist DA aas  dist angle  dist       angle   num
B0303-HOH O   B0001-  A O5* 3.17 HH  -2 -1.00  -1.0 -1.00  -1.0 126.2     1
B0285-HOH O   B0001-HOH N1  2.70 HH  -2 -1.00  -1.0 -1.00  -1.0 102.5     2
A0170-ARG NH2 B0002-  G O2P 2.55 SH  -2 -1.00 112.7  1.99 106.6 117.4     3
A0265-HOH O   B0002-  G O2P 2.98 HH  -2 -1.00  -1.0 -1.00  -1.0 127.5     4
A0279-HOH O   B0002-  U O2P 2.79 HH  -2 -1.00  -1.0 -1.00  -1.0 118.7     5
A0180-ARG NH2 B0002-LYS N7  2.71 SH  -2 -1.00 155.7  1.77 129.4 123.3     6
C0061-  G N4  B0002-  G O6  2.90 HH  -2 -1.00 169.9  1.91 122.7 122.0     7
A0180-ARG NH1 B0002-  G O6  2.91 SH  -2 -1.00 169.0  1.93 129.3 132.0     8
B0002-  G N1  C0061-  C N3  2.84 HH  -2 -1.00 178.0  1.84 120.7 117.4     9
B0002-  G N2  C0061-  U O2  2.67 HH  -2 -1.00 171.4  1.68 119.5 122.4    10
B0002-ARG N2  C0061-ARG O2  2.67 HH  -2 -1.00 171.4  1.68 119.5 122.4    11
B0303-HOH O   B0032-LYS N7  2.71 SH  -2 -1.00 155.7  1.77 129.4 123.3    12
B0027-ARG NH1 B0303-HOH O   2.71 SH  -2 -1.00 155.7  1.77 129.4 123.3    13
B0304-HOH O   B0003-  A O5* 3.17 HH  -2 -1.00  -1.0 -1.00  -1.0 126.2    14
B0028-ARG NH1 B0304-HOH O   2.71 SH  -2 -1.00 155.7  1.77 129.4 123.3    15
B0304-HOH O   B0002-  G O5* 3.17 HH  -2 -1.00  -1.0 -1.00  -1.0 126.2    16
"""
DB = "testdb.sqlite"

try:
    os.remove(DB)
except OSError: # no such file
    pass

testfile = open("TEST.hb2", "w")
testfile.write(TEST_CONTACT)
testfile.close()
c = ContactFile("TEST.hb2", bond_type="H", DB_NAME = DB)
c.save()

logging.getLogger("db_cleanup").setLevel(logging.DEBUG)

db_cleanup.main(["", DB])

#os.remove(DB)
os.remove("TEST.hb2")
